//
//  YKAccount.m
//  WeChat
//
//  Created by 吴高烽 on 16/5/22.
//  Copyright © 2016年 吴高烽. All rights reserved.
//

#import "YKAccount.h"
#define kUserKey @"user"
#define kPwdKey  @"psd"
#define kLoginKey @"login"
#define kRegisterUserKey @"registerUser"
#define kRegisterPwdKey @"registerPwd"
#define kRegisterState @"registerState"
static NSString *domain = @"gaofeng.local" ;
static NSString *host = @"127.0.0.1";
static int port = 5222 ;
@implementation YKAccount
+(instancetype)shareAccount{
    return [[self alloc]init];
}
#pragma mark - 分配内存，创建对象
+(instancetype)allocWithZone:(struct _NSZone *)zone{
    static YKAccount *account;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        account =[super allocWithZone:zone];
        NSUserDefaults  *defaults =[NSUserDefaults standardUserDefaults];
        account.loginUser = [defaults objectForKey:kUserKey];
        account.loginPwd =[defaults objectForKey:kPwdKey];
        account.login =[defaults boolForKey:kLoginKey];
        account.registerAccount =[defaults boolForKey:kRegisterState];
        account.registerPwd =[defaults objectForKey:kRegisterPwdKey];
        account.registerUser = [defaults objectForKey:kRegisterUserKey];
    });
    return account;
}

-(void)saveToSandBox{
    // 保存user pwd login
    NSUserDefaults  *defaults =[NSUserDefaults standardUserDefaults];
    [defaults setObject:self.loginUser forKey:kUserKey];
    [defaults setObject:self.loginPwd forKey:kPwdKey];
    [defaults setBool:self.isLogin forKey:kLoginKey];
    [defaults setObject:self.registerUser forKey:kRegisterUserKey];
    [defaults setObject:self.registerPwd  forKey:kRegisterPwdKey];
//    [defaults setBool:self.registerAccount forKey:kRegisterState];
    [defaults synchronize]; // 同步
}
-(NSString *)domain{
    return domain;
}
-(NSString *)host{
    return host;
}
-(int)port{
    return port;
}
@end
